//
//  LPFMainVC.swift
//  新浪微博
//
//  Created by mac on 16/4/16.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class LPFMainVC: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //初始化
        let tabbar = LPFTabBar()
        
        tabbar.lpfDeletate = self
        
        // self.tabBar  系统私有属性 不能直接设置
        // 通过kvc
        setValue(tabbar, forKey: "tabBar")
        
        //添加控制器
        addChildViewController(LPFHomeController(), imgName: "tabbar_message_center", title: "消息")
        addChildViewController(LPFMessageController(), imgName: "tabbar_home", title: "首页")
        addChildViewController(LPFDiscoverController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(LPFProfileController(), imgName: "tabbar_profile", title: "我的")
        
    }
    
    func addChildViewController(childController: UIViewController, imgName: String, title: String) {
        //图片
        childController.tabBarItem.image = UIImage(named: imgName)
        //设置选中图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        //设置title
        childController.title = title
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: childController))
    }
  
}
// MARK: - CZTabBarDelegate撰写按钮被点击
extension LPFMainVC: LPFTabBarDelegate{
    func composeButtonClick(){
        let composeVC = LPFComposeVC()
        presentViewController(UINavigationController(rootViewController: composeVC), animated: true, completion: nil)
    }
}
